set scheme plotplain

*Parameters--------------------------------------------------------------------
local exch=2288 //Exchange rate TSH per USD

*Leader predictions------------------------------------------------------------
use "${sdir}/Leaders_and_Owners_cln.dta", clear

*Rename and relabel------------------------------------------------------------
rename (s9_q_1_own q42_ldr)(wtp wtp_ldr)
replace wtp=wtp/`exch'
replace wtp_ldr=wtp_ldr/`exch'

*generate leader-wtp differences
gen wtp_dff=(wtp_ldr-wtp)
bysort trt_grp: egen wtp_dff_mn=mean(wtp_dff)
gen wtp_dff_dmnd= wtp_dff-wtp_dff_mn
gen wtp_dff_dmnd_abs=abs(wtp_dff_dmnd)
gen wtp_dff_abs=abs(wtp_dff)


*Make a table of treatment effects----------------------------------------------
local controls_lst gender_ldr q9_1_ldr q4_1_ldr surveyor_id_ldr 

*Mean shift
eststo pnl1_c1: reghdfe wtp_dff i.trt_grp_ldr, vce(cluster shina_leader_id) absorb(strata)
eststo pnl1_c2: reghdfe wtp_dff i.trt_grp_ldr, vce(cluster shina_leader_id) absorb(strata shina_id)
estadd local shina_fe="\checkmark"
eststo pnl1_c3: reghdfe wtp_dff i.trt_grp_ldr, vce(cluster shina_leader_id) absorb(strata shina_id#plot_id)
estadd local shina_fe="\checkmark"
estadd local plot_fe="\checkmark"
eststo pnl1_c4: reghdfe wtp_dff i.trt_grp_ldr, vce(cluster shina_leader_id) absorb(strata `controls_lst')
estadd local controls="\checkmark"
eststo pnl1_c5: reghdfe wtp_dff i.trt_grp_ldr, vce(cluster shina_leader_id) absorb(strata shina_id `controls_lst')
estadd local shina_fe="\checkmark"
estadd local controls="\checkmark"
eststo pnl1_c6: reghdfe wtp_dff i.trt_grp_ldr, vce(cluster shina_leader_id) absorb(strata shina_id#plot_id `controls_lst')
estadd local shina_fe="\checkmark"
estadd local plot_fe="\checkmark"
estadd local controls="\checkmark"


*Absolute deviations from treatment group mean
eststo pnl2_c1: reghdfe wtp_dff_dmnd_abs i.trt_grp_ldr, vce(cluster shina_leader_id) absorb(strata)
eststo pnl2_c2: reghdfe wtp_dff_dmnd_abs i.trt_grp_ldr, vce(cluster shina_leader_id) absorb(strata shina_id)
estadd local shina_fe="\checkmark"
eststo pnl2_c3: reghdfe wtp_dff_dmnd_abs i.trt_grp_ldr, vce(cluster shina_leader_id) absorb(strata shina_id#plot_id)
estadd local shina_fe="\checkmark"
estadd local plot_fe="\checkmark"
eststo pnl2_c4: reghdfe wtp_dff_dmnd_abs i.trt_grp_ldr, vce(cluster shina_leader_id) absorb(strata `controls_lst')
estadd local controls="\checkmark"
eststo pnl2_c5: reghdfe wtp_dff_dmnd_abs i.trt_grp_ldr, vce(cluster shina_leader_id) absorb(strata shina_id `controls_lst')
estadd local shina_fe="\checkmark"
estadd local controls="\checkmark"
eststo pnl2_c6: reghdfe wtp_dff_dmnd_abs i.trt_grp_ldr, vce(cluster shina_leader_id) absorb(strata shina_id#plot_id `controls_lst')
estadd local shina_fe="\checkmark"
estadd local plot_fe="\checkmark"
estadd local controls="\checkmark"


	
*write to file
local note ///
	This table presents estimates of treatment effects on leaders predictions. Each observation is a plot-leader pair. In panel A, the dependent variable is the prediction error: the difference between the leader's prediction and actual willingness-to-pay. In panel B, the dependent variable is the absolute demeaned error: the absolute value of the leader's prediction error minus the treatment group average prediction error. All columns represent regressions on treatment group dummies with different sets of controls. Leader randomization strata fixed effects are always included. Where indicated, regressions include shina (neighbourhood) fixed effects, plot fixed effects, and a set of controls (leader gender, leader household income bracket, a dummy for leader's home plot being surveyed, and fixed effects for the ID of the leader's surveyor). Standard errors in parentheses are clustered at leader level. \sym{*}\(p<0.10\),	\sym{**}\(p<0.05\), \sym{***}\(p<0.01\).
		
*put all panels together in one table
//top panel 
esttab pnl1* using "tables/predictions_wtp_treateffects.tex", ///
	star(* 0.10 ** 0.05 *** 0.01) ///
	order(2.trt_grp_ldr 1.trt_grp_ldr) ///
	stats(shina_fe plot_fe controls N r2, label("Shina FE" "Plot FE" "Controls" "Observations" "R\$^2\$")) ///
	se label wrap fragment ///
	nomtitles nobaselevels ///
	prehead("\def\sym#1{\ifmmode^{#1}\else\(^{#1}\)\fi} {\centering\begin{tabular}{l*{6}{c}} \hline\hline") ///
	posthead("\hline \\ \multicolumn{7}{l}{\textit{Panel A: Prediction error, dependent variable = \$\widehat{w}_{ol}-w_o\$}} \\\\[-1ex]") ///
	substitute(\_ _) ///
	replace 
*eststo clear

//bottom panel 
esttab pnl2* using "tables/predictions_wtp_treateffects.tex", ///
	star(* 0.10 ** 0.05 *** 0.01) ///
	order(2.trt_grp_ldr 1.trt_grp_ldr) ///
	stats(shina_fe plot_fe controls N r2, label("Shina FE" "Plot FE" "Controls" "Observations" "R\$^2\$")) ///
	se label wrap fragment ///
	nomtitles nonumbers nobaselevels ///
	posthead("\hline \\ \multicolumn{7}{l}{\textit{Panel B: Absolute demeaned error, dependent variable = \$abs[u_{ol}-\overline{u}_{T(l)}]\$}} \\\\[-1ex]") ///
	prefoot("\hline") ///
	substitute(\_ _) ///
	postfoot("\hline\hline \end{tabular}\par\medskip}{\footnotesize {\it Note: }`note'}") ///
	append
estimates clear


	



*------------------------------------------------------------------------------

*END--------
clear
